#!/usr/local/bin/python2
# -*- coding: UTF-8 -*-
import os
import sys 
import re

 
if __name__ == '__main__':
    aa=[]
    with open("./can_mac_layer.sv","r") as fp:
        tt = fp.read()
        sig_sq = re.compile(r"always \@ \(posedge clk or posedge rst\) begin *\n *if *\(rst\) *\n *(\w+) *<= (\S+); *\n *else if (.*)\n *\S+ *<= *(\S+); *\n *else if (.*)\n *\S+ *<= *(\S+); *\n *end") 
        rr = sig_sq.findall(tt)
        
        for yy in rr:
            print (yy[0] + " <= " + yy[2] + " ? ("  + yy[3] + ":( " + yy[4] + " ? " + yy[5] + " : " + yy[0] + "));")

        #sig_def
        #for yy in tt:
        #    p=re.match(r"(logic\s+)(\S+)\s*;",yy,re.M|re.I)
        #    if p:          
        #        aa.append(p.group(2))
        #        
        #sigs_def = ",".join(aa)
        #print sigs_def

